package com.star.common.orm.entity;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * 基础查询条件，PO依赖此类用于条件查询数据库
 *
 * @author zhouhengzhe
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class QueryParam implements Serializable {
    private static final long serialVersionUID = -5283460708108514233L;
    /**
     * 查询条件后缀：以该后缀结尾的参数，可以自动补充查询条件
     */
    public static final String START_QUERY = "Start";
    public static final String END_QUERY = "End";
    public static final String NOT_QUERY = "Not";
    public static final String IN_QUERY = "In";
    public static final String NOT_IN_QUERY = "NotIn";
    public static final String LIKE_QUERY = "Like";
    public static final String LIKE_LEFT_QUERY = "LikeLeft";
    public static final String LIKE_RIGHT_QUERY = "LikeRight";
    public static final String MIN_QUERY = "Min";
    public static final String MAX_QUERY = "Max";
    public static final String MIN_EQUALS_QUERY = "MinEq";
    public static final String MAX_EQUALS_QUERY = "MaxEq";
    public static final String NOT_NULL_QUERY = "NotNull";
    public static final String IS_NULL_QUERY = "IsNull";
    /**
     * 关键字查询
     */
    public static final String KEYWORDS_QUERY = "keywords";

    @ApiModelProperty("排序字段")
    protected List<SortParam> sorts;

    @ApiModelProperty("关键字，or查询")
    private Map<String, Object> keywords;

    @ApiModelProperty("当前页码，从1开始，默认1")
    protected Long page = 1L;

    @ApiModelProperty("每页显示记录数, 默认10")
    protected Long limit = 10L;

    public long getStartIndex() {
        return (this.page - 1L) * this.limit;
    }

    public long getEndIndex() {
        return this.getStartIndex() + this.limit;
    }

}